/*************************************************************************
	> File Name: 001.类外重载.cpp
	> Author: Maureen 
	> Mail: Maureen@qq.com 
	> Created Time: 五  1/ 7 10:23:40 2022
 ************************************************************************/

#include <iostream>
using namespace std;

class Point {
public:
    Point();
    Point(int x, int y);
private:
    friend Point operator+(const Point&, const Point&);
    friend ostream& operator<<(ostream&, const Point&);
    int x, y;
};


Point::Point() : Point(0, 0) {  }

Point::Point(int x, int y): x(x), y(y) {  }

//类外重载+
////第一个参数代表+号左边的变量，第二个代表+号右边的变量
Point operator+(const Point& lhs, const Point& rhs) {
    return Point(lhs.x + rhs.x, lhs.y + rhs.y);
}

//重载<<
//第一个参数代表<<运算符左边的变量，第二个代表<<运算符右边的变量
ostream& operator<<(ostream& out, const Point& rhs) {
    out << "(" << rhs.x << ", " << rhs.y << ")";
    return out;
}

int main() {
    Point p1(3, 4);
    Point p2(7, 9);
    Point p3 = p1 + p2;

    cout << p1 << endl; //(3, 4)
    cout << p2 << endl; //(7, 9)
    cout << p3 << endl;//(10, 13)
    
    return 0;
}
